﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>ControlGetList - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The ControlGetList function returns a list of items/rows from a ListView, ListBox, ComboBox, or DropDownList." />
<meta name="ahk:equiv-v1" content="commands/ControlGet.htm#List" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>ControlGetList</h1>

<p>Returns a list of items/rows from a ListView, ListBox, ComboBox, or DropDownList.</p>

<pre class="Syntax">List := <span class="func">ControlGetList</span>(<span class="optional">Options, Control, WinTitle, WinText, ExcludeTitle, ExcludeText</span>)</pre>

<h2 id="Parameters">参数</h2>
<dl>
    <dt>Options</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>Specifices what to retrieve if the control is a ListView (see below). For other control types, <em>Options</em> should be blank/empty.</p>
        <p>If the <em>Options</em> parameter is blank or omitted, all the text in the ListView is retrieved. Otherwise, specify zero or more of the following words, each separated from the next with a space or tab:</p>
        <p><strong>Selected:</strong> Returns only the selected (highlighted) rows rather than all rows. If none, the return value is blank.</p>
        <p><strong>Focused:</strong> Returns only the focused row. If none, the return value is blank.</p>
        <p id="ColN"><strong>Col4:</strong> Returns only the fourth column (field) rather than all columns (replace 4 with a number of your choice).</p>
        <p><strong>Count:</strong> Returns a single number that is the total number of rows in the ListView.</p>
        <p><strong>Count Selected:</strong> Returns the number of selected (highlighted) rows.</p>
        <p><strong>Count Focused:</strong> Returns the row number (position) of the focused row (0 if none).</p>
        <p><strong>Count Col:</strong> Returns the number of columns in the control (or -1 if the count cannot be determined).</p>
    </dd>
    <dt>Control</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a> or <a href="../Objects.htm">对象</a></p>
        控件的 ClassNN, 文本或 HWND, 或具有 <code>Hwnd</code> 属性的对象. 有关详情, 请参阅 <a href="Control.htm#Parameter">Control 参数</a>.</p>
    </dd>
    <dt>WinTitle</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p>
        <p>识别目标窗口的窗口标题或其他条件. 请参阅 <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
    </dd>
    <dt>WinText</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>如果存在, 此参数必须是目标窗口的单个文本元素的子字符串(和内置的 Window Spy 工具显示的一样). 如果 <a href="DetectHiddenText.htm">DetectHiddenText</a> 为 ON, 那么会检测隐藏文本元素.</p>
    </dd>
    <dt>ExcludeTitle</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>标题中含有此参数值的窗口将被排除.</p>
    </dd>
    <dt>ExcludeText</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>文本中含有此参数值的窗口将被排除.</p>
    </dd>
</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
<p>This function returns the list of items/rows from a ListView, ListBox, ComboBox, or DropDownList. For a ListView, within each row, each field (column) except the last will end with a tab character (`t). To access the items/rows individually, use a <a href="LoopParse.htm">parsing loop</a> as in <a href="#ExListView">示例 #1</a> and <a href="#ExComboBox">示例 #2</a>.</p>

<h2 id="Error_Handling">错误处理</h2>
<p>Upon success, <a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 0. Upon failure, it is set to 1 and the return value is blank. Failure occurs when: 1) the target window or control does not exist; 2) the target ListView is not of type SysListView32; 3) the process owning the ListView could not be opened, perhaps due to a lack of user permissions or because it is locked; 4) the <a href="#ColN">Col<em>N</em> option</a> specifies a nonexistent column.</p>
<p>如果检测到无效参数, 则抛出<a href="Catch.htm#RuntimeErrors">异常</a>.</p>

<h2 id="Remarks">备注</h2>
<p>Some applications store their ListView text privately, which prevents their text from being retrieved. In these cases, <a href="../misc/ErrorLevel.htm">ErrorLevel</a> will usually be set to 0 (indicating success) but all the retrieved fields will be empty.</p>
<p>The columns in a ListView can be resized via <a href="SendMessage.htm">SendMessage</a> as shown in this example:</p>
<pre>SendMessage(4126, 0, 80, "SysListView321", WinTitle)  <em>; 4126 is the message LVM_SETCOLUMNWIDTH.</em></pre>
<p>In the above, 0 indicates the first column (specify 1 for the second, 2 for the third, etc.) Also, 80 is the new width. Replace 80 with -1 to autosize the column. Replace it with -2 to do the same but also take into account the header text width.</p>
<p>窗口标题和文本是区分大小写的. 除非 <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> 被打开, 否则不会检测隐藏窗口.</p>

<h2 id="Related">相关</h2>
<p><a href="WinGetList.htm">WinGetList</a>, <a href="Control.htm">Control functions</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExListView">
<p><a href="#ExListView">#1</a>: Extracts the individual rows and fields out of a ListView:</p>
<pre>List := ControlGetList("Selected", "SysListView321", WinTitle)
Loop Parse, List, "`n"  <em>; Rows are delimited by linefeeds (`n).</em>
{
    RowNumber := A_Index
    Loop Parse, A_LoopField, A_Tab  <em>; Fields (columns) in each row are delimited by tabs (A_Tab).</em>
        MsgBox "Row #" RowNumber " Col #" A_Index " is " A_LoopField
}</pre>
</div>

<div class="ex" id="ExComboBox">
<p><a href="#ExComboBox">#2</a>: Accesses the items individually:</p>
<pre>List := ControlGetList("", "ComboBox1", WinTitle)
Loop Parse, List, "`n"
    MsgBox "Item number " A_Index " is " A_LoopField</pre>
</div>

</body>
</html>